import { observable, action, set } from "mobx-miniprogram";
import { getStorage } from "../utils/storage";
export const userStore = observable({
  // 定义响应式数据

  token: getStorage("token") || "",

  userInfo: getStorage("userInfo") || "",

  isLogin: !!getStorage("token"), // 关键：根据token自动判断

  setIsLogin: action(function (param) {
    this.isLogin = param;
  }),

  setToken: action(function (token) {
    this.token = token;
    this.isLogin = !!token; // token有值就登录，无值就未登录
  }),

  /**
   * @description 把参数 userInfo 存储到 userStore 中
   * @param {*} userInfo
   */
  setUserInfo: action(function (userInfo) {
    this.userInfo = userInfo;
  }),
});
